
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>php变量 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="04_php数据类型.html" />
    
    
    <link rel="prev" href="02_PHP基础语法.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    前言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="01_php介绍.html">
            
                <a href="01_php介绍.html">
            
                    
                    php基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="01_php介绍.html">
            
                <a href="01_php介绍.html">
            
                    
                    php介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="02_PHP基础语法.html">
            
                <a href="02_PHP基础语法.html">
            
                    
                    php基础语法
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2.3" data-path="03_php变量.html">
            
                <a href="03_php变量.html">
            
                    
                    php变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="04_php数据类型.html">
            
                <a href="04_php数据类型.html">
            
                    
                    php数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="05_php常量.html">
            
                <a href="05_php常量.html">
            
                    
                    php常量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="06_php运算符.html">
            
                <a href="06_php运算符.html">
            
                    
                    php运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="07_php流程控制.html">
            
                <a href="07_php流程控制.html">
            
                    
                    php流程控制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="08_php数组.html">
            
                <a href="08_php数组.html">
            
                    
                    php数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="09_php函数.html">
            
                <a href="09_php函数.html">
            
                    
                    php函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10" data-path="10_php面向对象.html">
            
                <a href="10_php面向对象.html">
            
                    
                    php面向对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.11" data-path="11_php命名空间.html">
            
                <a href="11_php命名空间.html">
            
                    
                    php命名空间
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.12" data-path="12_php日期和时间.html">
            
                <a href="12_php日期和时间.html">
            
                    
                    php日期时间
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.13" data-path="13_php表单.html">
            
                <a href="13_php表单.html">
            
                    
                    php表单
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.14" data-path="14_php包含文件.html">
            
                <a href="14_php包含文件.html">
            
                    
                    php包含文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.15" data-path="15_php常用函数.html">
            
                <a href="15_php常用函数.html">
            
                    
                    php常用函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.16" data-path="../php高级/16_php常用变量函数.md">
            
                <span>
            
                    
                    php常用变量函数
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../php高级/01_php错误与异常.html">
            
                <a href="../php高级/01_php错误与异常.html">
            
                    
                    php错误与异常
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../php高级/02_PhpStorm本地断点调试.html">
            
                <a href="../php高级/02_PhpStorm本地断点调试.html">
            
                    
                    PhpStorm本地断点调试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../php高级/03_php文件操作.html">
            
                <a href="../php高级/03_php文件操作.html">
            
                    
                    php文件操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../php高级/04_cookie机制.html">
            
                <a href="../php高级/04_cookie机制.html">
            
                    
                    cookie机制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../php高级/05_session.html">
            
                <a href="../php高级/05_session.html">
            
                    
                    session
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../php高级/06_php画图.html">
            
                <a href="../php高级/06_php画图.html">
            
                    
                    php画图
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../php高级/07_php加密机制.html">
            
                <a href="../php高级/07_php加密机制.html">
            
                    
                    php加密机制
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >php变量</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="php&#x53D8;&#x91CF;">PHP&#x53D8;&#x91CF;</h1>
<blockquote>
<p>&#x53D8;&#x91CF;&#x5B58;&#x50A8;&#x6570;&#x636E;&#x7684;&#x5BB9;&#x5668;</p>
</blockquote>
<h2 id="&#x53D8;&#x91CF;&#x547D;&#x540D;">&#x53D8;&#x91CF;&#x547D;&#x540D;</h2>
<p>PHP&#x4E2D;&#x53D8;&#x91CF;&#x540D;&#x79F0;&#x7528;$&#x548C;&#x6807;&#x8BC6;&#x7B26;&#x8868;&#x793A;&#xFF0C;&#x5E76;&#x9075;&#x5FAA;&#x4EE5;&#x4E0B;&#x7EA6;&#x5B9A;&#xFF1A;</p>
<ol>
<li>&#x5728;PHP&#x4E2D;&#x53D8;&#x91CF;&#x540D;&#x662F;&#x533A;&#x5206;&#x5927;&#x5C0F;&#x5199;&#x7684;&#x3002;</li>
<li>&#x53D8;&#x91CF;&#x540D;&#x5FC5;&#x987B;&#x662F;&#x4EE5;&#x7F8E;&#x5143;&#x7B26;($)&#x5F00;&#x5934;</li>
<li>&#x53D8;&#x91CF;&#x540D;&#x5FC5;&#x987B;&#x4EE5;&#x5B57;&#x6BCD;&#x6216;&#x8005;&#x4E0B;&#x5212;&#x7EBF;&#x5B57;&#x7B26;&#x5F00;&#x59CB;</li>
<li>&#x53D8;&#x91CF;&#x540D;&#x53EA;&#x80FD;&#x5305;&#x542B;&#x5B57;&#x6BCD;&#x6570;&#x5B57;&#x5B57;&#x7B26;&#x4EE5;&#x53CA;&#x4E0B;&#x5212;&#x7EBF;&#xFF08;A-z&#x3001;0-9 &#x548C; _ &#xFF09;</li>
<li>&#x53D8;&#x91CF;&#x540D;&#x4E0D;&#x80FD;&#x5305;&#x542B;&#x7A7A;&#x683C;&#x3001;&#x4E0D;&#x80FD;&#x4EE5;&#x6570;&#x5B57;&#x5F00;&#x5934;</li>
</ol>
<h2 id="&#x58F0;&#x660E;&#x53D8;&#x91CF;">&#x58F0;&#x660E;&#x53D8;&#x91CF;</h2>
<p>PHP &#x6CA1;&#x6709;&#x58F0;&#x660E;&#x53D8;&#x91CF;&#x7684;&#x547D;&#x4EE4;&#x3002;</p>
<p>&#x53D8;&#x91CF;&#x4F1A;&#x5728;&#x9996;&#x6B21;&#x4E3A;&#x5176;&#x8D4B;&#x503C;&#x65F6;&#x88AB;&#x521B;&#x5EFA;&#xFF1A;</p>
<pre><code>$x = 10;
$y = 20;
$sum = $x + $y ;
echo $sum;
</code></pre><blockquote>
<p>Note: $this &#x662F;&#x4E00;&#x4E2A;&#x7279;&#x6B8A;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x5B83;&#x4E0D;&#x80FD;&#x88AB;&#x8D4B;&#x503C;&#x3002;</p>
</blockquote>
<h2 id="&#x53D8;&#x91CF;&#x64CD;&#x4F5C;">&#x53D8;&#x91CF;&#x64CD;&#x4F5C;</h2>
<table>
<thead>
<tr>
<th style="text-align:left">&#x51FD;&#x6570;&#x540D;</th>
<th style="text-align:left">&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><code>gettype(var)</code></td>
<td style="text-align:left">&#x68C0;&#x6D4B;&#x53D8;&#x91CF;&#x7C7B;&#x578B;</td>
</tr>
<tr>
<td style="text-align:left"><code>isset(var)</code></td>
<td style="text-align:left">&#x68C0;&#x6D4B;&#x53D8;&#x91CF;&#x662F;&#x5426;&#x5B58;&#x5728;</td>
</tr>
<tr>
<td style="text-align:left"><code>unset(var)</code></td>
<td style="text-align:left">&#x9500;&#x6BC1;&#x53D8;&#x91CF;</td>
</tr>
<tr>
<td style="text-align:left"><code>empty(var)</code></td>
<td style="text-align:left">&#x5224;&#x65AD;&#x53D8;&#x91CF;&#x503C;&#x4E3A;&#x5426;&#x4E3A;&#x7A7A;</td>
</tr>
</tbody>
</table>
<h3 id="gettype-&#x68C0;&#x6D4B;&#x53D8;&#x91CF;&#x7C7B;&#x578B;">gettype &#x68C0;&#x6D4B;&#x53D8;&#x91CF;&#x7C7B;&#x578B;</h3>
<p>&#x901A;&#x8FC7;&#x51FD;&#x6570;<code>gettype(var)</code>&#x83B7;&#x53D6;&#x53D8;&#x91CF;&#x7C7B;&#x578B;&#x3002;</p>
<h4 id="&#x8BED;&#x6CD5;">&#x8BED;&#x6CD5;</h4>
<pre><code>string gettype ( mixed $var )
</code></pre><h4 id="&#x793A;&#x4F8B;">&#x793A;&#x4F8B;</h4>
<pre><code>$num = 100;
echo gettype($num); //integer
</code></pre><blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x4E0D;&#x8981;&#x4F7F;&#x7528; gettype() &#x6765;&#x6D4B;&#x8BD5;&#x67D0;&#x79CD;&#x7C7B;&#x578B;&#xFF0C;&#x56E0;&#x4E3A;&#x5176;&#x8FD4;&#x56DE;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x5728;&#x672A;&#x6765;&#x7684;&#x7248;&#x672C;&#x4E2D;&#x53EF;&#x80FD;&#x9700;&#x8981;&#x6539;&#x53D8;&#x3002;&#x6B64;&#x5916;&#xFF0C;&#x7531;&#x4E8E;&#x5305;&#x542B;&#x4E86;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x6BD4;&#x8F83;&#xFF0C;&#x5B83;&#x7684;&#x8FD0;&#x884C;&#x4E5F;&#x662F;&#x8F83;&#x6162;&#x7684;&#x3002; &#x63A8;&#x8350;&#x4F7F;&#x7528; is_* &#x51FD;&#x6570;&#x4EE3;&#x66FF;&#x3002;</p>
</blockquote>
<h3 id="isset-&#x68C0;&#x6D4B;&#x53D8;&#x91CF;&#x662F;&#x5426;&#x5B58;&#x5728;">isset &#x68C0;&#x6D4B;&#x53D8;&#x91CF;&#x662F;&#x5426;&#x5B58;&#x5728;</h3>
<p>&#x901A;&#x8FC7;&#x51FD;&#x6570;<code>isset(var)</code>&#x4E00;&#x822C;&#x7528;&#x6765;&#x68C0;&#x6D4B;&#x53D8;&#x91CF;&#x662F;&#x5426;&#x8BBE;&#x7F6E;&#x3002;</p>
<h4 id="&#x8BED;&#x6CD5;">&#x8BED;&#x6CD5;</h4>
<pre><code>bool isset ( mixed $var [, mixed $... ] )
</code></pre><h4 id="&#x53C2;&#x6570;">&#x53C2;&#x6570;</h4>
<table>
<thead>
<tr>
<th style="text-align:left">&#x53C2;&#x6570;</th>
<th style="text-align:left">&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">var</td>
<td style="text-align:left">&#x8981;&#x68C0;&#x67E5;&#x7684;&#x53D8;&#x91CF;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">...</td>
<td style="text-align:left">&#x5176;&#x4ED6;&#x53D8;&#x91CF;&#x3002;</td>
</tr>
</tbody>
</table>
<h4 id="&#x8FD4;&#x56DE;&#x503C;">&#x8FD4;&#x56DE;&#x503C;</h4>
<ul>
<li>&#x82E5;&#x53D8;&#x91CF;&#x4E0D;&#x5B58;&#x5728;&#x5219;&#x8FD4;&#x56DE; FALSE</li>
<li>&#x82E5;&#x53D8;&#x91CF;&#x5B58;&#x5728;&#x4E14;&#x5176;&#x503C;&#x4E3A;NULL&#xFF0C;&#x4E5F;&#x8FD4;&#x56DE; FALSE</li>
<li>&#x82E5;&#x53D8;&#x91CF;&#x5B58;&#x5728;&#x4E14;&#x503C;&#x4E0D;&#x4E3A;NULL&#xFF0C;&#x5219;&#x8FD4;&#x56DE; TURE &#x540C;&#x65F6;&#x68C0;&#x67E5;&#x591A;&#x4E2A;&#x53D8;&#x91CF;&#x65F6;&#xFF0C;&#x6BCF;&#x4E2A;&#x5355;&#x9879;&#x90FD;&#x7B26;&#x5408;&#x4E0A;&#x4E00;&#x6761;&#x8981;&#x6C42;&#x65F6;&#x624D;&#x8FD4;&#x56DE; TRUE&#xFF0C;&#x5426;&#x5219;&#x7ED3;&#x679C;&#x4E3A; FALSE</li>
</ul>
<h4 id="&#x793A;&#x4F8B;">&#x793A;&#x4F8B;</h4>
<pre><code>$num = 100;
echo isset($num);  //&#x5B58;&#x5728;&#x8FD4;&#x56DE; true
echo isset($link); //&#x4E0D;&#x5B58;&#x5728;&#x8FD4;&#x56DE; false
</code></pre><h3 id="unset-&#x9500;&#x6BC1;&#x53D8;&#x91CF;">unset &#x9500;&#x6BC1;&#x53D8;&#x91CF;</h3>
<p>&#x901A;&#x8FC7;&#x51FD;&#x6570;<code>unset(var)</code>&#x9500;&#x6BC1;&#x53D8;&#x91CF;&#x3002;</p>
<h4 id="&#x8BED;&#x6CD5;">&#x8BED;&#x6CD5;</h4>
<pre><code>void unset ( mixed $var [, mixed $... ] )
</code></pre><h4 id="&#x793A;&#x4F8B;">&#x793A;&#x4F8B;</h4>
<pre><code>$name = &quot;allcky&quot;;
unset($name); //&#x9500;&#x6BC1;&#x53D8;&#x91CF;
if($name){
    echo &quot;&#x53D8;&#x91CF;&#x5B58;&#x5728;&quot;;
}else{
    echo &quot;&#x53D8;&#x91CF;&#x5DF2;&#x9500;&#x6BC1;&quot;;
}
</code></pre><h3 id="&#x5224;&#x65AD;&#x503C;&#x662F;&#x5426;&#x4E3A;&#x7A7A;">&#x5224;&#x65AD;&#x503C;&#x662F;&#x5426;&#x4E3A;&#x7A7A;</h3>
<p>empty() &#x51FD;&#x6570; &#x5224;&#x65AD;&#x503C;&#x4E3A;&#x5426;&#x4E3A;&#x7A7A;</p>
<h4 id="&#x8BED;&#x6CD5;">&#x8BED;&#x6CD5;</h4>
<pre><code>bool empty ( mixed var )
</code></pre><p>&#x529F;&#x80FD;:&#x68C0;&#x67E5;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x662F;&#x5426;&#x4E3A;&#x7A7A;</p>
<h4 id="&#x89C4;&#x5219;">&#x89C4;&#x5219;</h4>
<ul>
<li>&#x82E5;&#x53D8;&#x91CF;&#x4E0D;&#x5B58;&#x5728;&#x5219;&#x8FD4;&#x56DE; <code>TRUE</code> &#x82E5;&#x53D8;&#x91CF;&#x5B58;&#x5728;&#x4E14;&#x5176;&#x503C;&#x4E3A;<code>&quot;&quot;</code>&#x3001;<code>0</code>&#x3001;<code>&quot;0&quot;</code>&#x3001;<code>NULL</code>&#x3001;&#x3001;<code>FALSE</code>&#x3001;<code>array()</code>&#x4EE5;&#x53CA;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x5C5E;&#x6027;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;true</li>
<li>&#x82E5;&#x53D8;&#x91CF;&#x5B58;&#x5728;&#x4E14;&#x503C;&#x4E0D;&#x4E3A;<code>&quot;&quot;</code>&#x3001;<code>0</code>&#x3001;<code>&quot;0&quot;</code>&#x3001;<code>NULL</code>&#x3001;&#x3001;<code>FALSE</code>&#x3001;<code>array()</code>&#x4EE5;&#x53CA;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x5C5E;&#x6027;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;false</li>
</ul>
<h2 id="&#x9884;&#x5B9A;&#x4E49;&#x53D8;&#x91CF;">&#x9884;&#x5B9A;&#x4E49;&#x53D8;&#x91CF;</h2>
<h3 id="server">$_SERVER[]</h3>
<table>
<thead>
<tr>
<th>&#x53D8;&#x91CF;&#x540D;&#x79F0;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>$_SERVER[&apos;SERVER_ADDR&apos;]</td>
<td>&#x5F53;&#x524D;&#x8FD0;&#x884C;&#x811A;&#x672C;&#x6240;&#x5728;&#x7684;&#x670D;&#x52A1;&#x5668;&#x7684;IP&#x5730;&#x5740;</td>
</tr>
<tr>
<td>$_SERVER[&apos;SERVER_NAME&apos;]</td>
<td>&#x5F53;&#x524D;&#x8FD0;&#x884C;&#x811A;&#x672C;&#x6240;&#x5728;&#x670D;&#x52A1;&#x5668;&#x4E3B;&#x673A;&#x7684;&#x540D;&#x79F0;</td>
</tr>
<tr>
<td>$_SERVER[&apos;SERVER_PORT&apos;]</td>
<td>&#x670D;&#x52A1;&#x5668;&#x6240;&#x4F7F;&#x7528;&#x7684;&#x7AEF;&#x53E3;&#x53F7;</td>
</tr>
<tr>
<td>$_SERVER[&apos;SCRIPT_NAME&apos;]</td>
<td>&#x83B7;&#x53D6;&#x76F8;&#x5BF9;&#x8DEF;&#x5F84;</td>
</tr>
<tr>
<td>$_SERVER[&apos;QUERY_STRING&apos;]</td>
<td>&#x67E5;&#x8BE2;&#x5B57;&#x7B26;&#x4E32;</td>
</tr>
<tr>
<td>$_SERVER[&apos;REQUEST_URI&apos;]</td>
<td>&#x8DEF;&#x5F84;&#x3001;&#x67E5;&#x8BE2;&#x5B57;&#x7B26;&#x4E32;</td>
</tr>
<tr>
<td>$_SERVER[&apos;REQUEST_METHOD&apos;]</td>
<td>&#x8BBF;&#x95EE;&#x9875;&#x9762;&#x65F6;&#x7684;&#x8BF7;&#x6C42;&#x65B9;&#x6CD5;&#x3002;&#x5982;&#xFF1A;GET&#x3001;POST</td>
</tr>
<tr>
<td>$_SERVER[&apos;REMOTE_ADDR&apos;]</td>
<td>&#x6B63;&#x5728;&#x6D4F;&#x89C8;&#x5F53;&#x524D;&#x9875;&#x9762;&#x7528;&#x6237;&#x7684;IP&#x5730;&#x5740;</td>
</tr>
<tr>
<td>$_SERVER[&apos;REMOTE_PORT&apos;]</td>
<td>&#x7528;&#x6237;&#x8FDE;&#x63A5;&#x5230;&#x670D;&#x52A1;&#x5668;&#x65F6;&#x4F7F;&#x7528;&#x7684;&#x7AEF;&#x53E3;&#x53F7;</td>
</tr>
<tr>
<td>$_SERVER[&apos;SCRIPT_FILENAME&apos;]</td>
<td>&#x5F53;&#x524D;&#x6267;&#x884C;&#x811A;&#x672C;&#x7684;&#x7EDD;&#x5BF9;&#x8DEF;&#x5F84;</td>
</tr>
</tbody>
</table>
<h2 id="&#x53EF;&#x53D8;&#x53D8;&#x91CF;">&#x53EF;&#x53D8;&#x53D8;&#x91CF;</h2>
<p>&#x53EF;&#x53D8;&#x53D8;&#x91CF;&#x662F;&#x4E00;&#x79CD;&#x72EC;&#x7279;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x5B83;&#x5141;&#x8BB8;&#x52A8;&#x6001;&#x7684;&#x6539;&#x53D8;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x7684;&#x540D;&#x79F0;&#x3002;&#x8BE5;&#x53D8;&#x91CF;&#x7684;&#x540D;&#x79F0;&#x7531;&#x53E6;&#x5916;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x7684;&#x503C;&#x6765;&#x786E;&#x5B9A;&#x3002;&#x5B9E;&#x73B0;&#x8FC7;&#x7A0B;&#x662F;&#x5728;&#x53D8;&#x91CF;&#x524D;&#x9762;&#x518D;&#x591A;&#x52A0;&#x4E00;&#x4E2A;$&#x7B26;&#x53F7;&#x3002;</p>
<pre><code class="lang-php">$hello = <span class="hljs-string">&quot;&#x4F60;&#x597D;&quot;</span>;
$nihao = <span class="hljs-string">&quot;hello&quot;</span>;
<span class="hljs-keyword">echo</span> $nihao; <span class="hljs-comment">//hello</span>
<span class="hljs-keyword">echo</span> $$nihao ; <span class="hljs-comment">//&#x4F60;&#x597D;</span>
</code></pre>
<h2 id="&#x53D8;&#x91CF;&#x5F15;&#x7528;">&#x53D8;&#x91CF;&#x5F15;&#x7528;</h2>
<p>PHP&#x7684;&#x5F15;&#x7528;&#x5141;&#x8BB8;&#x4F60;&#x7528;&#x4E24;&#x4E2A;&#x53D8;&#x91CF;&#x6765;&#x6307;&#x5411;&#x540C;&#x4E00;&#x4E2A;&#x5185;&#x5BB9;</p>
<pre><code class="lang-php">$a=<span class="hljs-string">&quot;ABC&quot;</span>;
$b =&amp;$a;
<span class="hljs-keyword">echo</span> $a;<span class="hljs-comment">//&#x8FD9;&#x91CC;&#x8F93;&#x51FA;:ABC</span>
<span class="hljs-keyword">echo</span> $b;<span class="hljs-comment">//&#x8FD9;&#x91CC;&#x8F93;&#x51FA;:ABC</span>
$b=<span class="hljs-string">&quot;EFG&quot;</span>;
<span class="hljs-keyword">echo</span> $a;<span class="hljs-comment">//&#x8FD9;&#x91CC;$a&#x7684;&#x503C;&#x53D8;&#x4E3A;EFG &#x6240;&#x4EE5;&#x8F93;&#x51FA;EFG echo $b;//&#x8FD9;&#x91CC;&#x8F93;&#x51FA;EFG</span>
</code></pre>
<h2 id="&#x53D8;&#x91CF;&#x4F5C;&#x7528;&#x57DF;">&#x53D8;&#x91CF;&#x4F5C;&#x7528;&#x57DF;</h2>
<p>&#x53D8;&#x91CF;&#x5728;&#x4F7F;&#x7528;&#x65F6;&#xFF0C;&#x8981;&#x7B26;&#x5408;&#x53D8;&#x91CF;&#x5B9A;&#x4E49;&#x89C4;&#x5219;&#xFF0C;&#x540C;&#x65F6;&#x53D8;&#x91CF;&#x5FC5;&#x987B;&#x5728;&#x6709;&#x6548;&#x8303;&#x56F4;&#x5185;&#x4F7F;&#x7528;&#xFF0C;&#x5982;&#x679C;&#x8D85;&#x51FA;&#x6709;&#x6548;&#x8303;&#x56F4;&#xFF0C;&#x53D8;&#x91CF;&#x4E5F;&#x5C31;&#x5931;&#x53BB;&#x610F;&#x4E49;&#x4E86;&#x3002;</p>
<table>
<thead>
<tr>
<th>&#x4F5C;&#x7528;&#x57DF;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>local&#x5C40;&#x90E8;&#x53D8;&#x91CF;</td>
<td>&#x5373;&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x5B9A;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x5176;&#x4F5C;&#x7528;&#x57DF;&#x4F4D;&#x4E8E;&#x6240;&#x5728;&#x51FD;&#x6570;</td>
</tr>
<tr>
<td>global&#x5168;&#x5C40;&#x53D8;&#x91CF;</td>
<td>&#x5373;&#x88AB;&#x5B9A;&#x4E49;&#x5728;&#x6240;&#x6709;&#x51FD;&#x6570;&#x4EE5;&#x5916;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x5176;&#x4F5C;&#x7528;&#x57DF;&#x662F;&#x6574;&#x4E2A;PHP&#x6587;&#x4EF6;&#xFF0C;&#x4F46;&#x662F;&#x5728;&#x7528;&#x6237;&#x5B9A;&#x4E49;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x662F;&#x4E0D;&#x53EF;&#x7528;&#x7684;&#xFF0C;&#x60F3;&#x8981;&#x5728;&#x7528;&#x6237;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x4F7F;&#x7528;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x8981;&#x7528; global&#x5173;&#x952E;&#x5B57;&#x58F0;&#x660E;</td>
</tr>
<tr>
<td>static&#x9759;&#x6001;&#x53D8;&#x91CF;</td>
<td>&#x80FD;&#x591F;&#x5728;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x7ED3;&#x675F;&#x540E;&#x4ECD;&#x4FDD;&#x7559;&#x53D8;&#x91CF;&#x503C;&#xFF0C;&#x5F53;&#x518D;&#x6B21;&#x56DE;&#x5230;&#x5176;&#x4F5C;&#x7528;&#x57DF;&#x65F6;&#xFF0C;&#x53C8;&#x53EF;&#x4EE5;&#x7EE7;&#x7EED;&#x4F7F;&#x7528;&#x539F;&#x6765;&#x7684;&#x503C;&#xFF0C;&#x800C;&#x4E00;&#x822C;&#x53D8;&#x91CF;&#x662F;&#x5728;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x7ED3;&#x675F;&#x540E;&#xFF0C;&#x5176;&#x5B58;&#x50A8;&#x7684;&#x6570;&#x503C;&#x5C06;&#x88AB;&#x6E05;&#x9664;&#xFF0C;&#x6240;&#x5360;&#x7684;&#x5185;&#x5B58;&#x7A7A;&#x95F4;&#x88AB;&#x91CA;&#x653E;&#xFF0C;&#x4F7F;&#x7528;&#x9759;&#x6001;&#x53D8;&#x91CF;&#x65F6;&#xFF0C;&#x5148;&#x8981;&#x7528;&#x5173;&#x952E;&#x5B57;static&#x6765;&#x58F0;&#x660E;&#x53D8;&#x91CF;&#xFF0C;&#x9700;&#x8981;&#x628A;static&#x653E;&#x5728;&#x8981;&#x5B9A;&#x4E49;&#x53D8;&#x91CF;&#x4E4B;&#x524D;</td>
</tr>
</tbody>
</table>
<h3 id="&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#x548C;&#x5C40;&#x90E8;&#x4F5C;&#x7528;&#x57DF;">&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#x548C;&#x5C40;&#x90E8;&#x4F5C;&#x7528;&#x57DF;</h3>
<h4 id="&#x5B9A;&#x4E49;">&#x5B9A;&#x4E49;</h4>
<ul>
<li>&#x5728;&#x6240;&#x6709;&#x51FD;&#x6570;&#x5916;&#x90E8;&#x5B9A;&#x4E49;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x62E5;&#x6709;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;global&#xFF1B;</li>
<li>&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x5B9A;&#x4E49;&#x7684;&#x53D8;&#x91CF;&#x7528;&#x4E8E;&#x5C40;&#x90E8;&#x4F5C;&#x7528;&#x57DF;local&#x3002;</li>
</ul>
<h4 id="&#x8BBF;&#x95EE;">&#x8BBF;&#x95EE;</h4>
<ul>
<li>&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x53EF;&#x4EE5;&#x88AB;&#x811A;&#x672C;&#x7684;&#x4EFB;&#x4F55;&#x4F4D;&#x7F6E;&#x8BBF;&#x95EE;&#xFF0C;&#x4F46;&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x8BBF;&#x95EE;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x8981;&#x4F7F;&#x7528;global&#x5173;&#x952E;&#x5B57;&#x3002;</li>
<li>&#x800C;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#x53EA;&#x80FD;&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x8FDB;&#x884C;&#x8BBF;&#x95EE;&#x3002;</li>
</ul>
<h3 id="&#x4F5C;&#x7528;&#x57DF;">&#x4F5C;&#x7528;&#x57DF;</h3>
<p>&#x80FD;&#x591F;&#x5728;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x7ED3;&#x675F;&#x540E;&#x4ECD;&#x4FDD;&#x7559;&#x53D8;&#x91CF;&#x503C;&#xFF0C;&#x5F53;&#x518D;&#x6B21;&#x56DE;&#x5230;&#x5176;&#x4F5C;&#x7528;&#x57DF;&#x65F6;&#xFF0C;&#x53C8;&#x53EF;&#x4EE5;&#x7EE7;&#x7EED;&#x4F7F;&#x7528;&#x539F;&#x6765;&#x7684;&#x503C;&#xFF0C;&#x800C;&#x4E00;&#x822C;&#x53D8;&#x91CF;&#x662F;&#x5728;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x7ED3;&#x675F;&#x540E;&#xFF0C;&#x5176;&#x5B58;&#x50A8;&#x7684;&#x6570;&#x503C;&#x5C06;&#x88AB;&#x6E05;&#x9664;&#xFF0C;&#x6240;&#x5360;&#x7684;&#x5185;&#x5B58;&#x7A7A;&#x95F4;&#x88AB;&#x91CA;&#x653E;&#xFF0C;&#x4F7F;&#x7528;&#x9759;&#x6001;&#x53D8;&#x91CF;&#x65F6;&#xFF0C;&#x5148;&#x8981;&#x7528;&#x5173;&#x952E;&#x5B57;static&#x6765;&#x58F0;&#x660E;&#x53D8;&#x91CF;&#xFF0C;&#x9700;&#x8981;&#x628A;static&#x653E;&#x5728;&#x8981;&#x5B9A;&#x4E49;&#x53D8;&#x91CF;&#x4E4B;&#x524D;</p>
<p>static&#x4F5C;&#x7528;&#x57DF;&#x7528;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</p>
<ol>
<li>static&#x653E;&#x5728;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x4FEE;&#x9970;&#x53D8;&#x91CF;</li>
<li>static&#x653E;&#x5728;&#x7C7B;&#x91CC;&#x4FEE;&#x9970;&#x5C5E;&#x6027;&#xFF0C;&#x6216;&#x65B9;&#x6CD5;</li>
<li>static&#x653E;&#x5728;&#x7C7B;&#x7684;&#x65B9;&#x6CD5;&#x91CC;&#x4FEE;&#x9970;&#x53D8;&#x91CF;</li>
<li>static&#x4FEE;&#x9970;&#x5728;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;&#x7684;&#x53D8;&#x91CF;</li>
</ol>
<h4 id="&#x5728;&#x51FD;&#x6570;&#x6267;&#x884C;&#x5B8C;&#x540E;&#xFF0C;&#x53D8;&#x91CF;&#x503C;&#x4ECD;&#x7136;&#x4FDD;&#x5B58;">&#x5728;&#x51FD;&#x6570;&#x6267;&#x884C;&#x5B8C;&#x540E;&#xFF0C;&#x53D8;&#x91CF;&#x503C;&#x4ECD;&#x7136;&#x4FDD;&#x5B58;</h4>
<p>&#x5982;&#x4E0B;&#x6240;&#x793A;&#xFF1A;</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">testStatic</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-keyword">static</span> $val = <span class="hljs-number">1</span>;
    <span class="hljs-keyword">echo</span> $val;
    $val++;
}
testStatic();   <span class="hljs-comment">//output 1</span>
testStatic();   <span class="hljs-comment">//output 2</span>
testStatic();   <span class="hljs-comment">//output 3</span>
</code></pre>
<h4 id="&#x4FEE;&#x9970;&#x5C5E;&#x6027;&#x6216;&#x65B9;&#x6CD5;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x7C7B;&#x540D;&#x8BBF;&#x95EE;&#xFF0C;&#x5982;&#x679C;&#x662F;&#x4FEE;&#x9970;&#x7684;&#x662F;&#x7C7B;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x4FDD;&#x7559;&#x503C;">&#x4FEE;&#x9970;&#x5C5E;&#x6027;&#x6216;&#x65B9;&#x6CD5;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x7C7B;&#x540D;&#x8BBF;&#x95EE;&#xFF0C;&#x5982;&#x679C;&#x662F;&#x4FEE;&#x9970;&#x7684;&#x662F;&#x7C7B;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x4FDD;&#x7559;&#x503C;</h4>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Person</span> </span>{
    <span class="hljs-keyword">static</span> $id = <span class="hljs-number">0</span>;

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">__construct</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">self</span>::$id++;
    }

    <span class="hljs-keyword">static</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getId</span><span class="hljs-params">()</span> </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">self</span>::$id;
    }
}
<span class="hljs-keyword">echo</span> Person::$id;   <span class="hljs-comment">//output 0</span>
<span class="hljs-keyword">echo</span> <span class="hljs-string">&quot;&lt;br/&gt;&quot;</span>;

$p1=<span class="hljs-keyword">new</span> Person();
$p2=<span class="hljs-keyword">new</span> Person();
$p3=<span class="hljs-keyword">new</span> Person();

<span class="hljs-keyword">echo</span> Person::$id;   <span class="hljs-comment">//output 3</span>
<span class="hljs-meta">?&gt;</span>
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="02_PHP基础语法.html" class="navigation navigation-prev " aria-label="Previous page: php基础语法">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="04_php数据类型.html" class="navigation navigation-next " aria-label="Next page: php数据类型">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"php变量","level":"1.2.3","depth":2,"next":{"title":"php数据类型","level":"1.2.4","depth":2,"path":"php/php基础/04_php数据类型.md","ref":"./php/php基础/04_php数据类型.md","articles":[]},"previous":{"title":"php基础语法","level":"1.2.2","depth":2,"path":"php/php基础/02_PHP基础语法.md","ref":"./php/php基础/02_PHP基础语法.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"php/php基础/03_php变量.md","mtime":"2020-04-23T09:59:52.383Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-04-23T11:06:38.883Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

